package com.app.chengbenyun.cailiao;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.app.chengbenyun.rengong.R;
import com.app.chengbenyun.rengong.RenGongDetailActivity;
import com.app.chengbenyun.rengong.RenGongSearchActivity;
import com.app.javabean.RenGongBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017-06-15.
 */
public class RuKuActivity extends AppCompatActivity {
    private ImageView back;
    private TextView title,text;
    private ListView list;
    private LinearLayout layout;
    private List<RenGongBean> rukus=new ArrayList<RenGongBean>();
    private String tables[]={"工种","本期金额","累计金额","可用余额"};

    BaseAdapter adapter=new BaseAdapter() {
        @Override
        public int getCount() {
//            return rukus.size()+1;
            return 6;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View view
                , ViewGroup parent) {
            view= LayoutInflater.from(RuKuActivity.this).inflate(R.layout.adapter_rengong,null);
            TextView cbs= (TextView) view.findViewById(R.id.chengbaoshang);
            TextView bz= (TextView) view.findViewById(R.id.banzu);
            TextView starttime= (TextView) view.findViewById(R.id.starttime);
            TextView endtime= (TextView) view.findViewById(R.id.endtime);
            TextView time= (TextView) view.findViewById(R.id.time);

            time.setVisibility(View.GONE);

            if(position==0){
                cbs.setText(tables[0]);
                bz.setText(tables[1]);
                starttime.setText(tables[2]);
                endtime.setText(tables[3]);
                cbs.setBackgroundResource(R.color.table_background);
                bz.setBackgroundResource(R.color.table_background);
                starttime.setBackgroundResource(R.color.table_background);
                endtime.setBackgroundResource(R.color.table_background);
                cbs.setTextColor(Color.WHITE);
                bz.setTextColor(Color.WHITE);
                starttime.setTextColor(Color.WHITE);
                endtime.setTextColor(Color.WHITE);
            }else{

            }

            return view;
        }
    };

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rengong);
        title= (TextView) findViewById(R.id.rengong_title);
        back= (ImageView) findViewById(R.id.rengong_back);
        layout= (LinearLayout) findViewById(R.id.rengong_layout);
        text= (TextView) findViewById(R.id.rengong_text);
        list= (ListView) findViewById(R.id.rengong_list);

        title.setText("入库单");
        text.setText("输入材料名称");
        list.setAdapter(adapter);
        back.setOnClickListener(clickListener);
        layout.setOnClickListener(clickListener);
        list.setOnItemClickListener(itemClickListener);
    }

    View.OnClickListener clickListener=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(v==back){
                finish();
            }else{
                Intent intent=new Intent(RuKuActivity.this, RenGongSearchActivity.class);
                intent.putExtra("flag","1");
                startActivity(intent);
            }
        }
    };

    AdapterView.OnItemClickListener itemClickListener=new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if(position!=0){
                Intent intent=new Intent(RuKuActivity.this,RenGongDetailActivity.class);
                intent.putExtra("flag","2");
                startActivity(intent);
            }
        }
    };
}
